<?php
/*
 * 用户操作
 */
class user extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('user_model');
		$this->load->model('tongji_model');
		$this->load->helper('url');
		$this->load->library('session');
	}
	/*
	 * 校验用户登录
	 */
	public function checklogin()
	{
		$yzm = $this->input->post('yzm');

		$this->load->helper(array('imgCode'));
		$imgcode = new imgcode();
		if($imgcode->check($yzm)){
			$flag = $this->user_model->model_checklogin();
			if($flag){
				header("Location: ../user/usermessage");
			}else{
				$alert_str ="登录错误！";
				$this->load->library('Tools');
				$this->tools->showMessage($alert_str,'back');
			}
		}else{
			$alert_str ="验证码错误！";
			$this->load->library('Tools');
			$this->tools->showMessage($alert_str,'back');
		}
	}

	/*
	 * 登出
	 */
	 public function loginout()
	 {
	 	$this->user_model->model_loginout();
		header("Location: ../../index.php");
	 }

	 /*
	  * 修改登录密码
	  *
	  */
	 public function changePwd()
	 {
		$flag = $this->user_model->model_changePwd();
		if($flag)
		{
			header("Location: ../tongji/main");
		}else{
			$this->tools->showMessage("输入的密码错误！");
		}

	 }
	 /**
	  * 用户注册
	  */
	 public function register()
	 {
	 	$newRegister = $this->input->post('newRegister');
		if($newRegister)
		{
			$flag = $this->user_model->model_newRegister();
			if($flag)
			{
				header("Location: ../user/usermessage");
			}
		}else{
			$this->load->view('user/register');
		}
	 }

	 	/*
	 * 修改登录密码
	 */
	 public function usepwd()
	 {
	 	$header['title'] = '修改登录密码';
		$header['location1'] = '系统功能';
		$header['location2'] = '修改登录密码';
	 	$data = array();
		$this->load->view('main/header',$header);
 		$this->load->view('user/usepwd',$data);
 		$this->load->view('main/footer');
	 }

	 	/*
	 * 查看嵌入代码
	 */
	public function showcode()
	{
		$header['title'] = '查看代码';
		$header['location1'] = '系统功能';
		$header['location2'] = '查看代码';
		$this->tongji_model->getWebSiteInfo();
		$data['style']= $this->tools->get_code($this->session->userdata('wid'),$this->session->userdata('uid'));
		$this->load->view('main/header',$header);
 		$this->load->view('user/showcode',$data);
 		$this->load->view('main/footer');
	}

	 /**
	  * 登录成功后，跳转至用户信息页面
	  */
	  public function usermessage()
	  {
		 $this->load->model('tongji_model');
		 $data['websitelist'] = $this->tongji_model->getUserWebsite();
		 $this->load->view('user/user_message',$data);
	  }

	  /**
	   * 用户协议
	   */
    public function agreement()
    {
   	 	$this->load->view('user/agreement');
    }

    /**
     * 免责申明
     */
    public function terms()
    {
    	$this->load->view('user/terms');
    }
}
?>
